﻿Imports System
Imports System.Globalization
Imports System.Workflow.Runtime.Tracking

Namespace System.Workflow.Runtime
    Friend Class TrackingChannelWrapper
        ' Methods
        Private Sub New()
        End Sub

        Public Sub New(ByVal channel As TrackingChannel, ByVal serviceType As Type, ByVal workflowType As Type, ByVal profile As RTTrackingProfile)
            Me._serviceType = serviceType
            Me._scheduleType = workflowType
            Me._channel = channel
            Me._profile = profile
            Me._profileVersionId = profile.Version
        End Sub

        Friend Function GetTrackingProfile(ByVal skedExec As WorkflowExecutor) As RTTrackingProfile
            If (Me._profile Is Nothing) Then
                Throw New InvalidOperationException(String.Format(CultureInfo.CurrentCulture, ExecutionStringManager.NullProfileForChannel, New Object() { Me._scheduleType.AssemblyQualifiedName }))
            End If
            Return Me._profile
        End Function

        Friend Sub MakeProfilePrivate(ByVal exec As WorkflowExecutor)
            If (Not Me._profile Is Nothing) Then
                If Not Me._profile.IsPrivate Then
                    Me._profile = Me._profile.Clone
                    Me._profile.IsPrivate = True
                End If
            Else
                Me._profile = Me.GetTrackingProfile(exec).Clone
                Me._profile.IsPrivate = True
            End If
        End Sub

        Friend Sub SetTrackingProfile(ByVal profile As RTTrackingProfile)
            Me._profile = profile
        End Sub


        ' Properties
        Friend ReadOnly Property TrackingChannel As TrackingChannel
            Get
                Return Me._channel
            End Get
        End Property

        Friend ReadOnly Property TrackingServiceType As Type
            Get
                Return Me._serviceType
            End Get
        End Property


        ' Fields
        Private _channel As TrackingChannel
        <NonSerialized> _
        Private _profile As RTTrackingProfile
        Private _profileVersionId As Version
        Private _scheduleType As Type
        Private _serviceType As Type
    End Class
End Namespace

